using B.S.Medical.Api.Read.Application.Command.Home;
using B.S.Medical.Api.Read.DTOS;
using B.S.Medical.ErrorCode;
using MediatR;
using Microsoft.AspNetCore.Mvc;

namespace B.S.Medical.Api.Read.Controllers
{
    /// <summary>
    /// 首页控制器
    /// </summary>
    [Route("api/[controller]/[action]")]
    [ApiController]
    public class HomeController : ControllerBase
    {
        private readonly IMediator mediator;

        public HomeController(IMediator mediator)
        {
            this.mediator = mediator;
        }

        /// <summary>
        /// 获取首页统计数据
        /// </summary>
        /// <returns>首页统计数据</returns>
        [HttpGet]
        public async Task<ApiResult<HomeStatisticsDto>> GetHomeStatistics()
        {
            var command = new GetHomeStatisticsCommand();
            return await mediator.Send(command);
        }

        /// <summary>
        /// 获取实时挂号数据
        /// </summary>
        /// <param name="limit">限制条数，默认10条</param>
        /// <returns>实时挂号数据</returns>
        [HttpGet]
        public async Task<ApiResult<List<RealTimeRegisterDto>>> GetRealTimeRegisters(int limit = 10)
        {
            var command = new GetRealTimeRegistersCommand { Limit = limit };
            return await mediator.Send(command);
        }

        /// <summary>
        /// 获取热门科室排行
        /// </summary>
        /// <param name="limit">限制条数，默认10条</param>
        /// <returns>热门科室排行</returns>
        [HttpGet]
        public async Task<ApiResult<List<HotDepartmentDto>>> GetHotDepartments(int limit = 10)
        {
            var command = new GetHotDepartmentsCommand { Limit = limit };
            return await mediator.Send(command);
        }

        /// <summary>
        /// 获取热门医生排行
        /// </summary>
        /// <param name="limit">限制条数，默认10条</param>
        /// <returns>热门医生排行</returns>
        [HttpGet]
        public async Task<ApiResult<List<HotDoctorDto>>> GetHotDoctors(int limit = 10)
        {
            var command = new GetHotDoctorsCommand { Limit = limit };
            return await mediator.Send(command);
        }

        /// <summary>
        /// 获取近7日挂号预约情况
        /// </summary>
        /// <returns>近7日挂号预约数据</returns>
        [HttpGet]
        public async Task<ApiResult<List<DailyRegisterDto>>> GetDailyRegisters()
        {
            var command = new GetDailyRegistersCommand();
            return await mediator.Send(command);
        }

        /// <summary>
        /// 获取近7日门诊充值趋势
        /// </summary>
        /// <returns>近7日门诊充值数据</returns>
        [HttpGet]
        public async Task<ApiResult<List<DailyRechargeDto>>> GetDailyRecharges()
        {
            var command = new GetDailyRechargesCommand();
            return await mediator.Send(command);
        }
    }
} 